package com.loongtech.bi.manager.game;

import com.loongtech.bi.action.PageHelper;
import com.loongtech.bi.entity.game.EntityNewRoleSchoolPassLevelDistribute;
import com.loongtech.bi.manager.system.BiPlatformManager;
import com.loongtech.bi.manager.system.GameParamConfigManager;
import com.loongtech.bi.support.CommonGameParam;
import com.loongtech.bi.support.chart.ChartData1;
import com.loongtech.bi.support.chart.ChartFlow;
import com.loongtech.bi.support.chart.ChartSelect;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 游戏内分析-等级分析manager
 * 
 * @author marin
 * @date 2015-09-15
 */
@Service
public class LevelGameManager extends ManagerQueryCacheBase<Object> {
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private ActiveUser1LevelDistributeManager activeUser1LevelDistributeManager;
	
	@Autowired
	private ActiveUser10LevelDistributeManager activeUser10LevelDistributeManager;
	
	@Autowired
	private NewUser1LevelDistributeManager newUser1LevelDistributeManager;
	
	@Autowired
    private UserSevenLoss1LevelDistributeManager userSevenLoss1LevelDistributeManager;

    @Autowired
    private UserSecondLoss1LevelDistributeManager userSecondLoss1LevelDistributeManager;

	@Autowired
    private NewRoleSchoolLevelDistributeManager newRoleSchoolLevelDistributeManager;

    @Autowired
    private NewRoleSchoolSecondLostLevelDistributeManager newRoleSchoolSecondLostLevelDistributeManager;

    @Autowired
    private ActiveRoleSchoolLevelDistributeManager activeRoleSchoolLevelDistributeManager;

    @Autowired
    private NewRoleSchoolPassLevelDistributeManager newRoleSchoolPassLevelDistributeManager;


    //新增用户1等级分布
    public List<UserSevenLoss1LevelDistributeData> getUserSecondLoss1LevelDistributeData(Date dateStart, Date dateEnd,String queryPlatform, String queryChannel, String queryServer) {
        List<UserSevenLoss1LevelDistributeData> result = new ArrayList<>();
        List<Object[]> sumUserNumberList = userSecondLoss1LevelDistributeManager.getAllKindUserNumber(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
        //
        List<Object[]> levelList = userSecondLoss1LevelDistributeManager.getAllKindUserNumberGroupByLevel(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
        //总人数
        Integer sumUserNumber = -1;

        if(sumUserNumberList != null && sumUserNumberList.size() > 0 && sumUserNumberList.get(0)[0] != null) {
            Integer number = Integer.parseInt(sumUserNumberList.get(0)[0].toString());

            sumUserNumber = number == null ? sumUserNumber : number;
        }

        for(Object[] o : levelList) {
            UserSevenLoss1LevelDistributeData u = new UserSevenLoss1LevelDistributeData();
            u.setPlatformId(queryPlatform);
            u.setChannelId(queryChannel);
            u.setServerId(queryServer);
            u.setDay(Time.getDateStr(dateStart));
            u.setLevel(Integer.parseInt(o[0].toString()));
            //
            Integer user_number = Integer.parseInt(o[1].toString());
            Float levelPercent = user_number.floatValue() / sumUserNumber.floatValue();
            u.setLevelPercent(PageHelper.floatKeep4Number(levelPercent));

            result.add(u);
        }

        Collections.sort(result, new UserSevenLoss1LevelDistributeData().comparatorNum);

        return result;
    }

	//新增用户1等级分布
    public List<UserSevenLoss1LevelDistributeData> getUserSevenLoss1LevelDistributeData(Date dateStart, Date dateEnd,String queryPlatform, String queryChannel, String queryServer) {
        List<UserSevenLoss1LevelDistributeData> result = new ArrayList<>();
        List<Object[]> sumUserNumberList = userSevenLoss1LevelDistributeManager.getAllKindUserNumber(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
        //
        List<Object[]> levelList = userSevenLoss1LevelDistributeManager.getAllKindUserNumberGroupByLevel(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
        //总人数
        Integer sumUserNumber = -1;

        if(sumUserNumberList != null && sumUserNumberList.size() > 0 && sumUserNumberList.get(0)[0] != null) {
            Integer number = Integer.parseInt(sumUserNumberList.get(0)[0].toString());

            sumUserNumber = number == null ? sumUserNumber : number;
        }

        for(Object[] o : levelList) {
            UserSevenLoss1LevelDistributeData u = new UserSevenLoss1LevelDistributeData();
            u.setPlatformId(queryPlatform);
            u.setChannelId(queryChannel);
            u.setServerId(queryServer);
            u.setDay(Time.getDateStr(dateStart));
            u.setLevel(Integer.parseInt(o[0].toString()));
            //
            Integer user_number = Integer.parseInt(o[1].toString());
            Float levelPercent = user_number.floatValue() / sumUserNumber.floatValue();
            u.setLevelPercent(PageHelper.floatKeep4Number(levelPercent));

            result.add(u);
        }

        Collections.sort(result, new UserSevenLoss1LevelDistributeData().comparatorNum);

        return result;
    }
	
	//用户7日流失1等级分布
	public class UserSevenLoss1LevelDistributeData {
		private String platformId;
		private String channelId;
		private String serverId;
		private String day; // 日期
		
		@ChartFlow(name="级别")
		private Integer level;
		@ChartSelect(name = "等级人数占比", key = 1)
		@ChartData1(name = "等级人数占比", key = 1)
		private Float levelPercent;
		
		// 比较器
		public final Comparator<UserSevenLoss1LevelDistributeData> comparatorNum = new Comparator<UserSevenLoss1LevelDistributeData>() {
			public int compare(UserSevenLoss1LevelDistributeData s1, UserSevenLoss1LevelDistributeData s2) {
				return s2.getLevel().compareTo(s1.getLevel());
			}
		};
		
		public String getPlatformId() {
			return platformId;
		}
		public void setPlatformId(String platformId) {
			this.platformId = platformId;
		}
		public String getChannelId() {
			return channelId;
		}
		public void setChannelId(String channelId) {
			this.channelId = channelId;
		}
		public String getServerId() {
			return serverId;
		}
		public void setServerId(String serverId) {
			this.serverId = serverId;
		}
		public String getDay() {
			return day;
		}
		public void setDay(String day) {
			this.day = day;
		}
		public Integer getLevel() {
			return level;
		}
		public void setLevel(Integer level) {
			this.level = level;
		}
		public Float getLevelPercent() {
			return levelPercent;
		}
		public void setLevelPercent(Float levelPercent) {
			this.levelPercent = levelPercent;
		}
	}
	
	//新增用户1等级分布
	public List<NewUser1LevelDistributeData> getNewUser1LevelDistributeData(Date dateStart, Date dateEnd,String queryPlatform, String queryChannel, String queryServer) {
		List<NewUser1LevelDistributeData> result = new ArrayList<>();
		List<Object[]> sumUserNumberList = newUser1LevelDistributeManager.getAllKindUserNumber(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
		//
		List<Object[]> levelList = newUser1LevelDistributeManager.getAllKindUserNumberGroupByLevel(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
		//总人数
		Integer sumUserNumber = -1;
		
		if(sumUserNumberList != null && sumUserNumberList.size() > 0 && sumUserNumberList.get(0)[0] != null) {
			Integer number = Integer.parseInt(sumUserNumberList.get(0)[0].toString());
			
			sumUserNumber = number == null ? sumUserNumber : number;
		}
				
		for(Object[] o : levelList) {
			NewUser1LevelDistributeData u = new NewUser1LevelDistributeData();
            u.setPlatformId(queryPlatform);
            u.setChannelId(queryChannel);
            u.setServerId(queryServer);
            u.setDay(Time.getDateStr(dateStart));
			u.setLevel(Integer.parseInt(o[0].toString()));
			//
			Integer user_number = Integer.parseInt(o[1].toString());
			Float levelPercent = user_number.floatValue() / sumUserNumber.floatValue();
			u.setLevelPercent(PageHelper.floatKeep4Number(levelPercent));
			
			result.add(u);
		}
		
		Collections.sort(result, new NewUser1LevelDistributeData().comparatorNum);
		
		return result;
	}

    public List<NewUser1LevelDistributeData1> getNewUser1LevelDistributeData1(Date dateStart, String queryPlatform, String queryChannel, String queryServer) {
        List<NewUser1LevelDistributeData1> result = new ArrayList<>();
        List<NewUser1LevelDistributeData> tmp = getNewUser1LevelDistributeData(dateStart, dateStart, queryPlatform, queryChannel, queryServer);
        for (NewUser1LevelDistributeData r : tmp) {
            NewUser1LevelDistributeData1 t = new NewUser1LevelDistributeData1();
            t.setPlatformId(r.getPlatformId());
            t.setChannelId(r.getChannelId());
            t.setServerId(r.getServerId());
            t.setDay(r.getDay());
            t.setLevel(r.getLevel());
            t.setLevelPercent(r.getLevelPercent());
            result.add(t);
        }

        Date yes = new Date(Time.getBeginningOfDay(dateStart.getTime() - Time.DAY));
        tmp = getNewUser1LevelDistributeData(yes, yes, queryPlatform, queryChannel, queryServer);
        for (NewUser1LevelDistributeData r : tmp) {
            NewUser1LevelDistributeData1 t = new NewUser1LevelDistributeData1();
            t.setPlatformId(r.getPlatformId());
            t.setChannelId(r.getChannelId());
            t.setServerId(r.getServerId());
            t.setDay(r.getDay());
            t.setLevel(r.getLevel());
            t.setLevelPercent(r.getLevelPercent());
            result.add(t);
        }

        Date last = new Date(Time.getBeginningOfDay(dateStart.getTime() -  7 *Time.DAY));
        tmp = getNewUser1LevelDistributeData(last, last, queryPlatform, queryChannel, queryServer);
        for (NewUser1LevelDistributeData r : tmp) {
            NewUser1LevelDistributeData1 t = new NewUser1LevelDistributeData1();
            t.setPlatformId(r.getPlatformId());
            t.setChannelId(r.getChannelId());
            t.setServerId(r.getServerId());
            t.setDay(r.getDay());
            t.setLevel(r.getLevel());
            t.setLevelPercent(r.getLevelPercent());
            result.add(t);
        }

        Collections.sort(result, new NewUser1LevelDistributeData1().comparatorNum);

        return result;
    }

	//
	public class NewUser1LevelDistributeData {
		private String platformId;
		private String channelId;
		private String serverId;
		private String day; // 日期
		
		@ChartFlow(name="级别")
		private Integer level;
		@ChartSelect(name = "等级人数占比", key = 1)
		@ChartData1(name = "等级人数占比", key = 1)
		private Float levelPercent;
		
		// 比较器
		public final Comparator<NewUser1LevelDistributeData> comparatorNum = new Comparator<NewUser1LevelDistributeData>() {
			public int compare(NewUser1LevelDistributeData s1, NewUser1LevelDistributeData s2) {
				return s2.getLevel().compareTo(s1.getLevel());
			}
		};
		
		public String getPlatformId() {
			return platformId;
		}
		public void setPlatformId(String platformId) {
			this.platformId = platformId;
		}
		public String getChannelId() {
			return channelId;
		}
		public void setChannelId(String channelId) {
			this.channelId = channelId;
		}
		public String getServerId() {
			return serverId;
		}
		public void setServerId(String serverId) {
			this.serverId = serverId;
		}
		public String getDay() {
			return day;
		}
		public void setDay(String day) {
			this.day = day;
		}
		public Integer getLevel() {
			return level;
		}
		public void setLevel(Integer level) {
			this.level = level;
		}
		public Float getLevelPercent() {
			return levelPercent;
		}
		public void setLevelPercent(Float levelPercent) {
			this.levelPercent = levelPercent;
		}
	}

	
	//1日
	public List<ActiveUser1LevelDistributeData> getActiveUser1LevelDistributeData(Date dayDate,String queryPlatform, String queryChannel, String queryServer) {
		List<ActiveUser1LevelDistributeData> result = new ArrayList<>();
		List<Object[]> sumUserNumberList = activeUser1LevelDistributeManager.getAllKindUserNumber(dayDate,queryPlatform, queryChannel, queryServer);
		//
		List<Object[]> levelList = activeUser1LevelDistributeManager.getAllKindUserNumberGroupByLevel(dayDate, queryPlatform, queryChannel, queryServer);
		//总人数
		Integer sumUserNumber = -1;
		
		if(sumUserNumberList != null && sumUserNumberList.size() > 0 && sumUserNumberList.get(0)[0] != null) {
			Integer number = Integer.parseInt(sumUserNumberList.get(0)[0].toString());
			
			sumUserNumber = number == null ? sumUserNumber : number;
		}
				
		for(Object[] o : levelList) {
			ActiveUser1LevelDistributeData u = new ActiveUser1LevelDistributeData();
			u.setPlatformId(queryPlatform);
			u.setChannelId(queryChannel);
			u.setServerId(queryServer);
            u.setDay(Time.getDateStr(dayDate));
			u.setLevel(Integer.parseInt(o[0].toString()));
			//
			Integer user_number = Integer.parseInt(o[1].toString());
			Float levelPercent = user_number.floatValue() / sumUserNumber.floatValue();
			u.setLevelPercent(PageHelper.floatKeep4Number(levelPercent));
			
			result.add(u);
		}
		
		Collections.sort(result, new ActiveUser1LevelDistributeData().comparatorNum);
		
		return result;
	}
	
	//10日
	public List<ActiveUser10LevelDistributeData> getActiveUser10LevelDistributeData(Date dayDate,String queryPlatform, String queryChannel, String queryServer) {
		Date dayStart = new Date(Time.getBeginningOfDay(dayDate.getTime() - 7 * Time.DAY));
		
		List<ActiveUser10LevelDistributeData> result = new ArrayList<>();
		List<Object[]> sumUserNumberList = activeUser10LevelDistributeManager.getAllKindUserNumber(dayStart, dayDate, queryPlatform, queryChannel, queryServer);
		//
		List<Object[]> levelList = activeUser10LevelDistributeManager.getAllKindUserNumberGroupByLevelName(dayStart, dayDate, queryPlatform, queryChannel, queryServer);
		
		//存levelList 数据的
		Map<DayAndLevelNameBean,Integer> dayAndLevelNameBeanMap = new HashMap<DayAndLevelNameBean,Integer>();
		Map<String,Integer> sumUserNUmberMap = new HashMap<String,Integer>();
		//
		for(Object[] o : levelList) {
			String day = o[0].toString();
			String levelName = o[1].toString();
			Integer userNumber = Integer.parseInt(o[2].toString());
			
			DayAndLevelNameBean dOayAndLevelNameBean = new DayAndLevelNameBean(day,levelName);
			dayAndLevelNameBeanMap.put(dOayAndLevelNameBean, userNumber);
		}
		
		for(Object[] o : sumUserNumberList) {
			String day = o[0].toString();
			Integer sumUserNumber = Integer.parseInt(o[1].toString());
			
			sumUserNUmberMap.put(day, sumUserNumber);
		}
		
		//迭代
		for(Map.Entry<DayAndLevelNameBean,Integer> entry : dayAndLevelNameBeanMap.entrySet()) {
			DayAndLevelNameBean dayAndLevelNameBean = entry.getKey();
			Integer userNumber = entry.getValue();
			
			ActiveUser10LevelDistributeData u = new ActiveUser10LevelDistributeData();
            u.setPlatformId(queryPlatform);
            u.setChannelId(queryChannel);
            u.setServerId(queryServer);
			u.setDay(dayAndLevelNameBean.getDay());
			u.setLevel_name(dayAndLevelNameBean.getLevelName());
			//
			Integer sumUserNUmber = sumUserNUmberMap.get(dayAndLevelNameBean.getDay());
			Float levelPercent = userNumber.floatValue() / sumUserNUmber.floatValue();
			u.setLevelPercent(PageHelper.floatKeep4Number(levelPercent));
			
			result.add(u);
		}
		
		Collections.sort(result, new ActiveUser10LevelDistributeData().comparatorLevelName);
		//Collections.sort(result, new ActiveUser10LevelDistributeData().comparatorDay);
		
		return result;
	}
	
	//
	public class ActiveUser1LevelDistributeData {
		private String platformId;
		private String channelId;
		private String serverId;
		private String day; // 日期
		
		@ChartFlow(name="级别")
		private Integer level;
		@ChartSelect(name = "等级人数占比", key = 1)
		@ChartData1(name = "等级人数占比", key = 1)
		private Float levelPercent;
		
		// 比较器
		public final Comparator<ActiveUser1LevelDistributeData> comparatorNum = new Comparator<ActiveUser1LevelDistributeData>() {
			public int compare(ActiveUser1LevelDistributeData s1, ActiveUser1LevelDistributeData s2) {
				return s2.getLevel().compareTo(s1.getLevel());
			}
		};
		
		public String getPlatformId() {
			return platformId;
		}
		public void setPlatformId(String platformId) {
			this.platformId = platformId;
		}
		public String getChannelId() {
			return channelId;
		}
		public void setChannelId(String channelId) {
			this.channelId = channelId;
		}
		public String getServerId() {
			return serverId;
		}
		public void setServerId(String serverId) {
			this.serverId = serverId;
		}
		public String getDay() {
			return day;
		}
		public void setDay(String day) {
			this.day = day;
		}
		public Integer getLevel() {
			return level;
		}
		public void setLevel(Integer level) {
			this.level = level;
		}
		public Float getLevelPercent() {
			return levelPercent;
		}
		public void setLevelPercent(Float levelPercent) {
			this.levelPercent = levelPercent;
		}
	}
	
	//
	public class ActiveUser10LevelDistributeData {
		private String platformId;
		private String channelId;
		private String serverId;
		private String day; // 日期
		
		@ChartFlow(name="级别")
		private String level_name;
		@ChartSelect(name = "等级人数占比", key = 1)
		@ChartData1(name = "等级人数占比", key = 1, multiByFiled = "day")
		private Float levelPercent;
		
		// 比较器
		public final Comparator<ActiveUser10LevelDistributeData> comparatorLevelName = new Comparator<ActiveUser10LevelDistributeData>() {
			public int compare(ActiveUser10LevelDistributeData s1, ActiveUser10LevelDistributeData s2) {
				int s1t = Integer.parseInt(s1.getLevel_name().split("-")[0]);
				int s2t = Integer.parseInt(s2.getLevel_name().split("-")[0]);
				
				if (s1t == s2t) {
					return s1.getDay().compareTo(s2.getDay());
				} else {
					return new Integer(s1t).compareTo(new Integer(s2t));
				}
			}
		};
		
		public String getPlatformId() {
			return platformId;
		}
		public void setPlatformId(String platformId) {
			this.platformId = platformId;
		}
		public String getChannelId() {
			return channelId;
		}
		public void setChannelId(String channelId) {
			this.channelId = channelId;
		}
		public String getServerId() {
			return serverId;
		}
		public void setServerId(String serverId) {
			this.serverId = serverId;
		}
		public String getDay() {
			return day;
		}
		public void setDay(String day) {
			this.day = day;
		}
		public Float getLevelPercent() {
			return levelPercent;
		}
		public void setLevelPercent(Float levelPercent) {
			this.levelPercent = levelPercent;
		}
		public String getLevel_name() {
			return level_name;
		}
		public void setLevel_name(String level_name) {
			this.level_name = level_name;
		}
	}

    public class NewUser1LevelDistributeData1 {
        private String platformId;
        private String channelId;
        private String serverId;
        private String day; // 日期

        @ChartFlow(name="级别")
        private Integer level;
        @ChartSelect(name = "新增用户等级人数占比", key = 1)
        @ChartData1(name = "新增用户等级人数占比", key = 1, multiByFiled = "day")
        private Float levelPercent;

        // 比较器
        public final Comparator<NewUser1LevelDistributeData1> comparatorNum = new Comparator<NewUser1LevelDistributeData1>() {
            public int compare(NewUser1LevelDistributeData1 s1, NewUser1LevelDistributeData1 s2) {
                return s1.getLevel().compareTo(s2.getLevel());
            }
        };

        public String getPlatformId() {
            return platformId;
        }
        public void setPlatformId(String platformId) {
            this.platformId = platformId;
        }
        public String getChannelId() {
            return channelId;
        }
        public void setChannelId(String channelId) {
            this.channelId = channelId;
        }
        public String getServerId() {
            return serverId;
        }
        public void setServerId(String serverId) {
            this.serverId = serverId;
        }
        public String getDay() {
            return day;
        }
        public void setDay(String day) {
            this.day = day;
        }
        public Integer getLevel() {
            return level;
        }
        public void setLevel(Integer level) {
            this.level = level;
        }
        public Float getLevelPercent() {
            return levelPercent;
        }
        public void setLevelPercent(Float levelPercent) {
            this.levelPercent = levelPercent;
        }
    }
	
	public class DayAndLevelNameBean {
		private String day;
		private String levelName;
		
		public DayAndLevelNameBean(String day, String levelName) {
			super();
			this.day = day;
			this.levelName = levelName;
		}
		
		public String getDay() {
			return day;
		}
		public void setDay(String day) {
			this.day = day;
		}
		public String getLevelName() {
			return levelName;
		}
		public void setLevelName(String levelName) {
			this.levelName = levelName;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((day == null) ? 0 : day.hashCode());
			result = prime * result
					+ ((levelName == null) ? 0 : levelName.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			DayAndLevelNameBean other = (DayAndLevelNameBean) obj;
			if (day == null) {
				if (other.day != null)
					return false;
			} else if (!day.equals(other.day))
				return false;
			if (levelName == null) {
				if (other.levelName != null)
					return false;
			} else if (!levelName.equals(other.levelName))
				return false;
			return true;
		}

		@Override
		public String toString() {
			return "DayAndLevelNameBean [day=" + day + ", levelName=" + levelName + "]";
		}
	}



    public List<NewRoleSchoolLevelDistributeData> getNewRoleSchoolLevelDistributeData(Date dateStart,String queryPlatform, String queryChannel, String queryServer, String queryJob) {
        List<NewRoleSchoolLevelDistributeData> result = new ArrayList<>();
        List<Object[]> sumRoleNumberList = newRoleSchoolLevelDistributeManager.getAllKindRoleNumber(dateStart, queryPlatform, queryChannel, queryServer, queryJob);
        List<Object[]> levelList = newRoleSchoolLevelDistributeManager.getAllKindRoleNumberGroupByLevel(dateStart, queryPlatform, queryChannel, queryServer, queryJob);
        //总人数
        Integer sumRoleNumber = -1;
        if(sumRoleNumberList != null && sumRoleNumberList.size() > 0 && sumRoleNumberList.get(0)[0] != null) {
            Integer number = Integer.parseInt(sumRoleNumberList.get(0)[0].toString());
            sumRoleNumber = number == null ? sumRoleNumber : number;
        }

        for(Object[] o : levelList) {
            NewRoleSchoolLevelDistributeData u = new NewRoleSchoolLevelDistributeData();
            u.setPlatformId(queryPlatform);
            u.setChannelId(queryChannel);
            u.setServerId(queryServer);
            u.setDay(Time.getDateStr(dateStart));
            u.setLevel(Integer.parseInt(o[0].toString()));
            u.setSchool(Integer.parseInt(queryJob));
            u.setSchoolName(GameParamConfigManager.getItemsRevise(CommonGameParam.SCHOOL).get(queryJob).replace("未知", "全部"));
            Integer role_number = Integer.parseInt(o[1].toString());
            u.setNum(role_number);
            Float levelPercent = role_number.floatValue() / sumRoleNumber.floatValue();
            u.setLevelPercent(PageHelper.floatKeep4Number(levelPercent));

            result.add(u);
        }

        Collections.sort(result, new NewRoleSchoolLevelDistributeData().comparatorNum);

        return result;
    }

    public List<NewRoleSchoolLevelDistributeData> getNewRoleSchoolLevelDistributeDatas(Date dateStart, String queryPlatform, String queryChannel, String queryServer, String queryJob, Date dateStart1, String queryPlatform1, String queryChannel1, String queryServer1, String queryJob1) {
        List<NewRoleSchoolLevelDistributeData> result = new ArrayList<>();
        List<NewRoleSchoolLevelDistributeData> tmp = getNewRoleSchoolLevelDistributeData(dateStart, queryPlatform, queryChannel, queryServer, queryJob);
        for (NewRoleSchoolLevelDistributeData r : tmp) {
            NewRoleSchoolLevelDistributeData t = new NewRoleSchoolLevelDistributeData();
            t.setPlatformId(r.getPlatformId());
            t.setChannelId(r.getChannelId());
            t.setServerId(r.getServerId());
            t.setDay(r.getDay());
            t.setLevel(r.getLevel());
            t.setSchool(r.getSchool());
            t.setSchoolName(r.getSchoolName());
            t.setNum(r.getNum());
            t.setLevelPercent(r.getLevelPercent());
            result.add(t);
        }

        tmp = getNewRoleSchoolLevelDistributeData(dateStart1, queryPlatform1, queryChannel1, queryServer1, queryJob1);
        for (NewRoleSchoolLevelDistributeData r : tmp) {
            NewRoleSchoolLevelDistributeData t = new NewRoleSchoolLevelDistributeData();
            t.setPlatformId(r.getPlatformId());
            t.setChannelId(r.getChannelId());
            t.setServerId(r.getServerId());
            t.setDay(r.getDay());
            t.setLevel(r.getLevel());
            t.setSchool(r.getSchool());
            t.setSchoolName(r.getSchoolName());
            t.setNum(r.getNum());
            t.setLevelPercent(r.getLevelPercent());
            result.add(t);
        }

        Collections.sort(result, new NewRoleSchoolLevelDistributeData().comparatorNum);

        return result;
    }

    public class NewRoleSchoolLevelDistributeData {
        private String platformId;
        private String channelId;
        private String serverId;
        private String platformName;
        private String channelName;
        private String serverName;
        private String day; // 日期

        @ChartFlow(name="角色等级")
        private Integer level;
        private Integer school;
        private String schoolName;
        @ChartSelect(name = "新增角色职业等级人数占比", key = 1)
        @ChartData1(name = "新增角色职业等级人数占比", key = 1, multiByFiled = "day", legendPrefix="schoolName")
        private Float levelPercent;
        @ChartSelect(name = "新增角色职业等级人数占比2", key = 2)
        @ChartData1(name = "新增角色职业等级人数占比2", key = 2, multiByFiled = "schoolName", legendPrefix="day")
        private Float levelPercent2;
        @ChartSelect(name = "新增角色职业等级人数占比3", key = 3)
        @ChartData1(name = "新增角色职业等级人数占比3", key = 3, multiByFiled = "platformName", legendPrefix="schoolName")
        private Float levelPercent3;
        @ChartSelect(name = "新增角色职业等级人数占比4", key = 4)
        @ChartData1(name = "新增角色职业等级人数占比4", key = 4, multiByFiled = "channelName", legendPrefix="schoolName")
        private Float levelPercent4;
        @ChartSelect(name = "新增角色职业等级人数占比5", key = 5)
        @ChartData1(name = "新增角色职业等级人数占比5", key = 5, multiByFiled = "serverName", legendPrefix="schoolName")
        private Float levelPercent5;

        private int num;

        // 比较器
        public final Comparator<NewRoleSchoolLevelDistributeData> comparatorNum = new Comparator<NewRoleSchoolLevelDistributeData>() {
            public int compare(NewRoleSchoolLevelDistributeData s1, NewRoleSchoolLevelDistributeData s2) {
                return s1.getLevel().compareTo(s2.getLevel());
            }
        };

        public String getPlatformId() {
            return platformId;
        }
        public void setPlatformId(String platformId) {
            this.platformId = platformId;
            this.platformName = BiPlatformManager.getPlatformNameById(platformId);
        }
        public String getChannelId() {
            return channelId;
        }
        public void setChannelId(String channelId) {
            this.channelId = channelId;
            this.channelName =  BiPlatformManager.getChannelNameById(channelId);
        }
        public String getServerId() {
            return serverId;
        }
        public void setServerId(String serverId) {
            this.serverId = serverId;
            this.serverName =  BiPlatformManager.getServerNameById(serverId);
        }
        public String getDay() {
            return day;
        }
        public void setDay(String day) {
            this.day = day;
        }
        public Integer getLevel() {
            return level;
        }
        public void setLevel(Integer level) {
            this.level = level;
        }
        public Float getLevelPercent() {
            return levelPercent;
        }
        public void setLevelPercent(Float levelPercent) {
            this.levelPercent = levelPercent;
            this.levelPercent2 = levelPercent;
            this.levelPercent3 = levelPercent;
            this.levelPercent4 = levelPercent;
            this.levelPercent5 = levelPercent;
        }

        public Integer getSchool() {
            return school;
        }

        public void setSchool(Integer school) {
            this.school = school;
        }

        public String getSchoolName() {
            return schoolName;
        }

        public void setSchoolName(String schoolName) {
            this.schoolName = schoolName;
        }

        public Float getLevelPercent2() {
            return levelPercent2;
        }

        public void setLevelPercent2(Float levelPercent2) {
            this.levelPercent2 = levelPercent2;
        }

        public String getPlatformName() {
            return platformName;
        }

        public void setPlatformName(String platformName) {
            this.platformName = platformName;
        }

        public String getChannelName() {
            return channelName;
        }

        public void setChannelName(String channelName) {
            this.channelName = channelName;
        }

        public String getServerName() {
            return serverName;
        }

        public void setServerName(String serverName) {
            this.serverName = serverName;
        }

        public Float getLevelPercent3() {
            return levelPercent3;
        }

        public void setLevelPercent3(Float levelPercent3) {
            this.levelPercent3 = levelPercent3;
        }

        public Float getLevelPercent4() {
            return levelPercent4;
        }

        public void setLevelPercent4(Float levelPercent4) {
            this.levelPercent4 = levelPercent4;
        }

        public Float getLevelPercent5() {
            return levelPercent5;
        }

        public void setLevelPercent5(Float levelPercent5) {
            this.levelPercent5 = levelPercent5;
        }

        public int getNum() {
            return num;
        }

        public void setNum(int num) {
            this.num = num;
        }
    }

    public List<NewRoleSchoolSecondLossLevelDistributeData> getNewRoleSchoolSecondLossLevelDistributeData(Date dateStart, String queryPlatform, String queryChannel, String queryServer, String queryJob) {
        List<NewRoleSchoolSecondLossLevelDistributeData> result = new ArrayList<>();
        List<Object[]> sumRoleNumberList = newRoleSchoolSecondLostLevelDistributeManager.getAllKindRoleNumber(dateStart, queryPlatform, queryChannel, queryServer, queryJob);
        List<Object[]> levelList = newRoleSchoolSecondLostLevelDistributeManager.getAllKindRoleNumberGroupByLevel(dateStart, queryPlatform, queryChannel, queryServer, queryJob);
        //总人数
        Integer sumRoleNumber = -1;
        if(sumRoleNumberList != null && sumRoleNumberList.size() > 0 && sumRoleNumberList.get(0)[0] != null) {
            Integer number = Integer.parseInt(sumRoleNumberList.get(0)[0].toString());
            sumRoleNumber = number == null ? sumRoleNumber : number;
        }

        for(Object[] o : levelList) {
            NewRoleSchoolSecondLossLevelDistributeData u = new NewRoleSchoolSecondLossLevelDistributeData();
            u.setPlatformId(queryPlatform);
            u.setChannelId(queryChannel);
            u.setServerId(queryServer);
            u.setDay(Time.getDateStr(dateStart));
            u.setLevel(Integer.parseInt(o[0].toString()));
            u.setSchool(Integer.parseInt(queryJob));
            u.setSchoolName(GameParamConfigManager.getItemsRevise(CommonGameParam.SCHOOL).get(queryJob).replace("未知", "全部"));
            Integer role_number = Integer.parseInt(o[1].toString());
            u.setNum(role_number);
            Float levelPercent = role_number.floatValue() / sumRoleNumber.floatValue();
            u.setLevelPercent(PageHelper.floatKeep4Number(levelPercent));

            result.add(u);
        }

        Collections.sort(result, new NewRoleSchoolSecondLossLevelDistributeData().comparatorNum);
        return result;
    }

    public List<NewRoleSchoolSecondLossLevelDistributeData> getNewRoleSchoolSecondLostLevelDistributeDatas(Date dateStart, String queryPlatform, String queryChannel, String queryServer, String queryJob, Date dateStart1, String queryPlatform1, String queryChannel1, String queryServer1, String queryJob1) {
        List<NewRoleSchoolSecondLossLevelDistributeData> result = new ArrayList<>();
        List<NewRoleSchoolSecondLossLevelDistributeData> tmp = getNewRoleSchoolSecondLossLevelDistributeData(dateStart, queryPlatform, queryChannel, queryServer, queryJob);
        for (NewRoleSchoolSecondLossLevelDistributeData r : tmp) {
            NewRoleSchoolSecondLossLevelDistributeData t = new NewRoleSchoolSecondLossLevelDistributeData();
            t.setPlatformId(r.getPlatformId());
            t.setChannelId(r.getChannelId());
            t.setServerId(r.getServerId());
            t.setDay(r.getDay());
            t.setLevel(r.getLevel());
            t.setSchool(r.getSchool());
            t.setSchoolName(r.getSchoolName());
            t.setNum(r.getNum());
            t.setLevelPercent(r.getLevelPercent());
            result.add(t);
        }

        tmp = getNewRoleSchoolSecondLossLevelDistributeData(dateStart1, queryPlatform1, queryChannel1, queryServer1, queryJob1);
        for (NewRoleSchoolSecondLossLevelDistributeData r : tmp) {
            NewRoleSchoolSecondLossLevelDistributeData t = new NewRoleSchoolSecondLossLevelDistributeData();
            t.setPlatformId(r.getPlatformId());
            t.setChannelId(r.getChannelId());
            t.setServerId(r.getServerId());
            t.setDay(r.getDay());
            t.setLevel(r.getLevel());
            t.setSchool(r.getSchool());
            t.setSchoolName(r.getSchoolName());
            t.setNum(r.getNum());
            t.setLevelPercent(r.getLevelPercent());
            result.add(t);
        }

        Collections.sort(result, new NewRoleSchoolSecondLossLevelDistributeData().comparatorNum);
        return result;
    }

    public class NewRoleSchoolSecondLossLevelDistributeData {
        private String platformId;
        private String channelId;
        private String serverId;
        private String platformName;
        private String channelName;
        private String serverName;
        private String day; // 日期

        @ChartFlow(name="角色等级")
        private Integer level;
        private Integer school;
        private String schoolName;
        private int num;
        @ChartSelect(name = "次日流失新增角色职业等级人数占比", key = 1)
        @ChartData1(name = "次日流失新增角色等级人数占比", key = 1, multiByFiled = "day", legendPrefix="schoolName")
        private Float levelPercent;
        @ChartSelect(name = "次日流失新增角色职业等级人数占比2", key = 2)
        @ChartData1(name = "次日流失新增角色等级人数占比2", key = 2, multiByFiled = "schoolName", legendPrefix="day")
        private Float levelPercent2;
        @ChartSelect(name = "次日流失新增角色职业等级人数占比3", key = 3)
        @ChartData1(name = "次日流失新增角色职业等级人数占比3", key = 3, multiByFiled = "platformName", legendPrefix="schoolName")
        private Float levelPercent3;
        @ChartSelect(name = "次日流失新增角色职业等级人数占比4", key = 4)
        @ChartData1(name = "次日流失新增角色职业等级人数占比4", key = 4, multiByFiled = "channelName", legendPrefix="schoolName")
        private Float levelPercent4;
        @ChartSelect(name = "次日流失新增角色职业等级人数占比5", key = 5)
        @ChartData1(name = "次日流失新增角色职业等级人数占比5", key = 5, multiByFiled = "serverName", legendPrefix="schoolName")
        private Float levelPercent5;

        // 比较器
        public final Comparator<NewRoleSchoolSecondLossLevelDistributeData> comparatorNum = new Comparator<NewRoleSchoolSecondLossLevelDistributeData>() {
            public int compare(NewRoleSchoolSecondLossLevelDistributeData s1, NewRoleSchoolSecondLossLevelDistributeData s2) {
                return s1.getLevel().compareTo(s2.getLevel());
            }
        };

        public String getPlatformId() {
            return platformId;
        }
        public void setPlatformId(String platformId) {
            this.platformId = platformId;
            this.platformName = BiPlatformManager.getPlatformNameById(platformId);
        }
        public String getChannelId() {
            return channelId;
        }
        public void setChannelId(String channelId) {
            this.channelId = channelId;
            this.channelName =  BiPlatformManager.getChannelNameById(channelId);
        }
        public String getServerId() {
            return serverId;
        }
        public void setServerId(String serverId) {
            this.serverId = serverId;
            this.serverName =  BiPlatformManager.getServerNameById(serverId);
        }
        public String getDay() {
            return day;
        }
        public void setDay(String day) {
            this.day = day;
        }
        public Integer getLevel() {
            return level;
        }
        public void setLevel(Integer level) {
            this.level = level;
        }
        public Float getLevelPercent() {
            return levelPercent;
        }
        public void setLevelPercent(Float levelPercent) {
            this.levelPercent = levelPercent;
            this.levelPercent2 = levelPercent;
            this.levelPercent3 = levelPercent;
            this.levelPercent4 = levelPercent;
            this.levelPercent5 = levelPercent;
        }

        public Integer getSchool() {
            return school;
        }

        public void setSchool(Integer school) {
            this.school = school;
        }

        public String getSchoolName() {
            return schoolName;
        }

        public void setSchoolName(String schoolName) {
            this.schoolName = schoolName;
        }

        public Float getLevelPercent2() {
            return levelPercent2;
        }

        public void setLevelPercent2(Float levelPercent2) {
            this.levelPercent2 = levelPercent2;
        }

        public String getPlatformName() {
            return platformName;
        }

        public void setPlatformName(String platformName) {
            this.platformName = platformName;
        }

        public String getChannelName() {
            return channelName;
        }

        public void setChannelName(String channelName) {
            this.channelName = channelName;
        }

        public String getServerName() {
            return serverName;
        }

        public void setServerName(String serverName) {
            this.serverName = serverName;
        }

        public Float getLevelPercent3() {
            return levelPercent3;
        }

        public void setLevelPercent3(Float levelPercent3) {
            this.levelPercent3 = levelPercent3;
        }

        public Float getLevelPercent4() {
            return levelPercent4;
        }

        public void setLevelPercent4(Float levelPercent4) {
            this.levelPercent4 = levelPercent4;
        }

        public Float getLevelPercent5() {
            return levelPercent5;
        }

        public void setLevelPercent5(Float levelPercent5) {
            this.levelPercent5 = levelPercent5;
        }

        public int getNum() {
            return num;
        }

        public void setNum(int num) {
            this.num = num;
        }
    }

    public List<ActiveRoleSchoolLevelDistributeData> getActiveRoleSchoolLevelDistributeData(Date dateStart,String queryPlatform, String queryChannel, String queryServer, String queryJob) {
        List<ActiveRoleSchoolLevelDistributeData> result = new ArrayList<>();
        List<Object[]> sumRoleNumberList = activeRoleSchoolLevelDistributeManager.getAllKindRoleNumber(dateStart, queryPlatform, queryChannel, queryServer, queryJob);
        List<Object[]> levelList = activeRoleSchoolLevelDistributeManager.getAllKindRoleNumberGroupByLevel(dateStart, queryPlatform, queryChannel, queryServer, queryJob);
        //总人数
        Integer sumRoleNumber = -1;
        if(sumRoleNumberList != null && sumRoleNumberList.size() > 0 && sumRoleNumberList.get(0)[0] != null) {
            Integer number = Integer.parseInt(sumRoleNumberList.get(0)[0].toString());
            sumRoleNumber = number == null ? sumRoleNumber : number;
        }

        for(Object[] o : levelList) {
            ActiveRoleSchoolLevelDistributeData u = new ActiveRoleSchoolLevelDistributeData();
            u.setPlatformId(queryPlatform);
            u.setChannelId(queryChannel);
            u.setServerId(queryServer);
            u.setDay(Time.getDateStr(dateStart));
            u.setLevel(Integer.parseInt(o[0].toString()));
            u.setSchool(Integer.parseInt(queryJob));
            u.setSchoolName(GameParamConfigManager.getItemsRevise(CommonGameParam.SCHOOL).get(queryJob).replace("未知", "全部"));
            Integer role_number = Integer.parseInt(o[1].toString());
            u.setNum(role_number);
            Float levelPercent = role_number.floatValue() / sumRoleNumber.floatValue();
            u.setLevelPercent(PageHelper.floatKeep4Number(levelPercent));

            result.add(u);
        }

        Collections.sort(result, new ActiveRoleSchoolLevelDistributeData().comparatorNum);

        return result;
    }

    public List<ActiveRoleSchoolLevelDistributeData> getActiveRoleSchoolLevelDistributeDatas(Date dateStart, String queryPlatform, String queryChannel, String queryServer, String queryJob, Date dateStart1, String queryPlatform1, String queryChannel1, String queryServer1, String queryJob1) {
        List<ActiveRoleSchoolLevelDistributeData> result = new ArrayList<>();
        List<ActiveRoleSchoolLevelDistributeData> tmp = getActiveRoleSchoolLevelDistributeData(dateStart, queryPlatform, queryChannel, queryServer, queryJob);
        for (ActiveRoleSchoolLevelDistributeData r : tmp) {
            ActiveRoleSchoolLevelDistributeData t = new ActiveRoleSchoolLevelDistributeData();
            t.setPlatformId(r.getPlatformId());
            t.setChannelId(r.getChannelId());
            t.setServerId(r.getServerId());
            t.setDay(r.getDay());
            t.setLevel(r.getLevel());
            t.setSchool(r.getSchool());
            t.setSchoolName(r.getSchoolName());
            t.setNum(r.getNum());
            t.setLevelPercent(r.getLevelPercent());
            result.add(t);
        }

        tmp = getActiveRoleSchoolLevelDistributeData(dateStart1, queryPlatform1, queryChannel1, queryServer1, queryJob1);
        for (ActiveRoleSchoolLevelDistributeData r : tmp) {
            ActiveRoleSchoolLevelDistributeData t = new ActiveRoleSchoolLevelDistributeData();
            t.setPlatformId(r.getPlatformId());
            t.setChannelId(r.getChannelId());
            t.setServerId(r.getServerId());
            t.setDay(r.getDay());
            t.setLevel(r.getLevel());
            t.setSchool(r.getSchool());
            t.setSchoolName(r.getSchoolName());
            t.setNum(r.getNum());
            t.setLevelPercent(r.getLevelPercent());
            result.add(t);
        }

        Collections.sort(result, new ActiveRoleSchoolLevelDistributeData().comparatorNum);

        return result;
    }

    public class ActiveRoleSchoolLevelDistributeData {
        private String platformId;
        private String channelId;
        private String serverId;
        private String platformName;
        private String channelName;
        private String serverName;
        private String day; // 日期

        @ChartFlow(name="角色等级")
        private Integer level;
        private Integer school;
        private String schoolName;
        @ChartSelect(name = "活跃角色职业等级人数占比", key = 1)
        @ChartData1(name = "活跃角色职业等级人数占比", key = 1, multiByFiled = "day", legendPrefix="schoolName")
        private Float levelPercent;
        @ChartSelect(name = "活跃角色职业等级人数占比2", key = 2)
        @ChartData1(name = "活跃角色职业等级人数占比2", key = 2, multiByFiled = "schoolName", legendPrefix="day")
        private Float levelPercent2;
        @ChartSelect(name = "活跃角色职业等级人数占比3", key = 3)
        @ChartData1(name = "活跃角色职业等级人数占比3", key = 3, multiByFiled = "platformName", legendPrefix="schoolName")
        private Float levelPercent3;
        @ChartSelect(name = "活跃角色职业等级人数占比4", key = 4)
        @ChartData1(name = "活跃角色职业等级人数占比4", key = 4, multiByFiled = "channelName", legendPrefix="schoolName")
        private Float levelPercent4;
        @ChartSelect(name = "活跃角色职业等级人数占比5", key = 5)
        @ChartData1(name = "活跃角色职业等级人数占比5", key = 5, multiByFiled = "serverName", legendPrefix="schoolName")
        private Float levelPercent5;

        private int num;

        // 比较器
        public final Comparator<ActiveRoleSchoolLevelDistributeData> comparatorNum = new Comparator<ActiveRoleSchoolLevelDistributeData>() {
            public int compare(ActiveRoleSchoolLevelDistributeData s1, ActiveRoleSchoolLevelDistributeData s2) {
                return s1.getLevel().compareTo(s2.getLevel());
            }
        };

        public String getPlatformId() {
            return platformId;
        }
        public void setPlatformId(String platformId) {
            this.platformId = platformId;
            this.platformName = BiPlatformManager.getPlatformNameById(platformId);
        }
        public String getChannelId() {
            return channelId;
        }
        public void setChannelId(String channelId) {
            this.channelId = channelId;
            this.channelName = BiPlatformManager.getChannelNameById(channelId);
        }
        public String getServerId() {
            return serverId;
        }
        public void setServerId(String serverId) {
            this.serverId = serverId;
            this.serverName = BiPlatformManager.getServerNameById(serverId);
        }
        public String getDay() {
            return day;
        }
        public void setDay(String day) {
            this.day = day;
        }
        public Integer getLevel() {
            return level;
        }
        public void setLevel(Integer level) {
            this.level = level;
        }
        public Float getLevelPercent() {
            return levelPercent;
        }
        public void setLevelPercent(Float levelPercent) {
            this.levelPercent = levelPercent;
            this.levelPercent2 = levelPercent;
            this.levelPercent3 = levelPercent;
            this.levelPercent4 = levelPercent;
            this.levelPercent5 = levelPercent;
        }

        public Integer getSchool() {
            return school;
        }

        public void setSchool(Integer school) {
            this.school = school;
        }

        public String getSchoolName() {
            return schoolName;
        }

        public void setSchoolName(String schoolName) {
            this.schoolName = schoolName;
        }

        public Float getLevelPercent2() {
            return levelPercent2;
        }

        public void setLevelPercent2(Float levelPercent2) {
            this.levelPercent2 = levelPercent2;
        }

        public String getPlatformName() {
            return platformName;
        }

        public void setPlatformName(String platformName) {
            this.platformName = platformName;
        }

        public String getChannelName() {
            return channelName;
        }

        public void setChannelName(String channelName) {
            this.channelName = channelName;
        }

        public String getServerName() {
            return serverName;
        }

        public void setServerName(String serverName) {
            this.serverName = serverName;
        }

        public Float getLevelPercent3() {
            return levelPercent3;
        }

        public void setLevelPercent3(Float levelPercent3) {
            this.levelPercent3 = levelPercent3;
        }

        public Float getLevelPercent4() {
            return levelPercent4;
        }

        public void setLevelPercent4(Float levelPercent4) {
            this.levelPercent4 = levelPercent4;
        }

        public Float getLevelPercent5() {
            return levelPercent5;
        }

        public void setLevelPercent5(Float levelPercent5) {
            this.levelPercent5 = levelPercent5;
        }

        public int getNum() {
            return num;
        }

        public void setNum(int num) {
            this.num = num;
        }
    }

    public List<RoleSchoolLevelPassRadioData> getRoleSchoolLevelPassRadioDatas(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer, String queryJob) {
        List<RoleSchoolLevelPassRadioData> result = new ArrayList<>();
        Map<String, Map<Integer, RoleSchoolLevelPassRadioData>> tmpResult = new LinkedHashMap<>();  // 日期：（等级：e）
        Map<String, Map<Integer, Map<Integer, List<EntityNewRoleSchoolPassLevelDistribute>>>> tmp = new LinkedHashMap<>();  // 日期：（等级：（类型：es）） 类型即passtype

        List<EntityNewRoleSchoolPassLevelDistribute> list = newRoleSchoolPassLevelDistributeManager.getAllKindRoleNumberGroupByLevel(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, queryJob);
        if (list == null || list.size() <= 0) {
            return result;
        }
        for (EntityNewRoleSchoolPassLevelDistribute entry : list) {
            String date = Time.getDateStr(entry.getDay());
            int level = entry.getLevel();
            int passtype = entry.getPasstype();
            Map<Integer, Map<Integer, List<EntityNewRoleSchoolPassLevelDistribute>>> ll = tmp.get(date);
            if (ll == null) {
                ll = new LinkedHashMap<>();
                tmp.put(date, ll);
            }
            Map<Integer, List<EntityNewRoleSchoolPassLevelDistribute>> lp = ll.get(level);
            if (lp == null) {
                lp = new LinkedHashMap<>();
                ll.put(level, lp);
            }
            List<EntityNewRoleSchoolPassLevelDistribute> ls = lp.get(passtype);
            if (ls == null) {
                ls = new ArrayList<>();
                lp.put(passtype, ls);
            }

            ls.add(entry);
        }

        for (Map.Entry<String, Map<Integer, Map<Integer, List<EntityNewRoleSchoolPassLevelDistribute>>>> entry : tmp.entrySet()) {
            String date = entry.getKey();
            Map<Integer, RoleSchoolLevelPassRadioData> tmpll = tmpResult.get(date);
            if (tmpll == null) {
                tmpll = new LinkedHashMap<>();
                tmpResult.put(date, tmpll);
            }
            Map<Integer, Map<Integer, List<EntityNewRoleSchoolPassLevelDistribute>>> ll = entry.getValue();
            for (Map.Entry<Integer, Map<Integer, List<EntityNewRoleSchoolPassLevelDistribute>>> entry1 : ll.entrySet()) {
                int level = entry1.getKey();
                RoleSchoolLevelPassRadioData rslpd = tmpll.get(level);
                if (rslpd == null) {
                    rslpd = new RoleSchoolLevelPassRadioData();
                    tmpll.put(level, rslpd);
                }
                rslpd.setDay(date);
                rslpd.setPlatformId(queryPlatform);
                rslpd.setChannelId(queryChannel);
                rslpd.setServerId(queryServer);
                rslpd.setLevel(level);
                rslpd.setSchool(Integer.parseInt(queryJob));
                rslpd.setSchoolName(GameParamConfigManager.getItemsRevise(CommonGameParam.SCHOOL).get(queryJob).replace("未知", "全部"));

                Map<Integer, List<EntityNewRoleSchoolPassLevelDistribute>> lp = entry1.getValue();
                for (Map.Entry<Integer, List<EntityNewRoleSchoolPassLevelDistribute>> entry2 : lp.entrySet()) {
                    int passtype = entry2.getKey();
                    List<EntityNewRoleSchoolPassLevelDistribute> ls = entry2.getValue();
                    int num = 0;
                    for (EntityNewRoleSchoolPassLevelDistribute l : ls) {
                        num += l.getUser_number();
                    }

                    if (1 == passtype) {
                        rslpd.setFirstDayPassNum(num);
                    } else if (7 == passtype) {
                        rslpd.setFirstWeekPassNum(num);
                    } else if (14 == passtype) {
                        rslpd.setSecondWeekPassNum(num);
                    } else if (30 == passtype) {
                        rslpd.setFirstMonthPassNum(num);
                    }
                }
            }
        }

        for (Map.Entry<String, Map<Integer, RoleSchoolLevelPassRadioData>> entry : tmpResult.entrySet()) {
            Map<Integer, RoleSchoolLevelPassRadioData> ll = entry.getValue();

            int maxLevel = 0;
            int minLevel = Integer.MAX_VALUE;
            for (Integer l : ll.keySet()) {
                maxLevel = l > maxLevel ? l : maxLevel;
                minLevel = l < minLevel ? l : minLevel;
            }
            RoleSchoolLevelPassRadioData min = ll.get(minLevel);

            for (int i = 1; i <= maxLevel; i++) {
                RoleSchoolLevelPassRadioData e = ll.get(i);
                if (i == maxLevel) {
                    e.setFirstDayPassRadio(PageHelper.floatKeep4Number(0f));
                    e.setFirstWeekPassRadio(PageHelper.floatKeep4Number(0f));
                    e.setSecondWeekPassRadio(PageHelper.floatKeep4Number(0f));
                    e.setFirstMonthPassRadio(PageHelper.floatKeep4Number(0f));

                    result.add(e);
                    break;
                }
                if (e == null) {
                    e.setFirstDayPassRadio(PageHelper.floatKeep4Number(1f));
                    e.setFirstWeekPassRadio(PageHelper.floatKeep4Number(1f));
                    e.setSecondWeekPassRadio(PageHelper.floatKeep4Number(1f));
                    e.setFirstMonthPassRadio(PageHelper.floatKeep4Number(1f));

                    result.add(e);
                } /*else {
                    for (int j = i + 1; j <= maxLevel; j++) {
                        RoleSchoolLevelPassRadioData e1 = ll.get(j);
                        if (e1 != null) {
                            e.setFirstDayPassRadio(PageHelper.floatKeep4Number(e.getFirstDayPassNum() == 0 ? 1f : (float)(e1.getFirstDayPassNum() * 1.0 / e.getFirstDayPassNum())));
                            e.setFirstWeekPassRadio(PageHelper.floatKeep4Number(e.getFirstWeekPassNum() == 0 ? 1f : (float)(e1.getFirstWeekPassNum() * 1.0 / e.getFirstWeekPassNum())));
                            e.setSecondWeekPassRadio(PageHelper.floatKeep4Number(e.getSecondWeekPassNum() == 0 ? 1f : (float)(e1.getSecondWeekPassNum() * 1.0 / e.getSecondWeekPassNum())));
                            e.setFirstMonthPassRadio(PageHelper.floatKeep4Number(e.getFirstMonthPassNum() == 0 ? 1f : (float)(e1.getFirstMonthPassNum() * 1.0 / e.getFirstMonthPassNum())));

                            result.add(e);
                            break;
                        }
                    }
                }*/ else {
                    e.setFirstDayPassRadio(PageHelper.floatKeep4Number(min.getFirstDayPassNum() == 0 ? 1f : (float)(e.getFirstDayPassNum() * 1.0 / min.getFirstDayPassNum())));
                    e.setFirstWeekPassRadio(PageHelper.floatKeep4Number(min.getFirstWeekPassNum() == 0 ? 1f : (float)(e.getFirstWeekPassNum() * 1.0 / min.getFirstWeekPassNum())));
                    e.setSecondWeekPassRadio(PageHelper.floatKeep4Number(min.getSecondWeekPassNum() == 0 ? 1f : (float)(e.getSecondWeekPassNum() * 1.0 / min.getSecondWeekPassNum())));
                    e.setFirstMonthPassRadio(PageHelper.floatKeep4Number(min.getFirstMonthPassNum() == 0 ? 1f : (float)(e.getFirstMonthPassNum() * 1.0 / min.getFirstMonthPassNum())));

                    result.add(e);
                }
            }
        }

        return result;
    }

    public class RoleSchoolLevelPassRadioData {
        private String platformId;
        private String channelId;
        private String serverId;
        private String platformName;
        private String channelName;
        private String serverName;
        private String day;
        private int level;
        private int school;
        private String schoolName;
        private int num;
        private float firstDayPassRadio;
        private float firstWeekPassRadio;
        private float secondWeekPassRadio;
        private float firstMonthPassRadio;
        private int firstDayPassNum;
        private int firstWeekPassNum;
        private int secondWeekPassNum;
        private int firstMonthPassNum;

        public String getPlatformName() {
            return platformName;
        }

        public void setPlatformName(String platformName) {
            this.platformName = platformName;
        }

        public String getChannelName() {
            return channelName;
        }

        public void setChannelName(String channelName) {
            this.channelName = channelName;
        }

        public String getServerName() {
            return serverName;
        }

        public void setServerName(String serverName) {
            this.serverName = serverName;
        }

        // 比较器
        public final Comparator<RoleSchoolLevelPassRadioData> comparatorNum = new Comparator<RoleSchoolLevelPassRadioData>() {
            public int compare(RoleSchoolLevelPassRadioData s1, RoleSchoolLevelPassRadioData s2) {
                return Integer.valueOf(s1.getLevel()).compareTo(Integer.valueOf(s2.getLevel()));
            }
        };

        public String getPlatformId() {
            return platformId;
        }
        public void setPlatformId(String platformId) {
            this.platformId = platformId;
            this.platformName = BiPlatformManager.getPlatformNameById(platformId);
        }
        public String getChannelId() {
            return channelId;
        }
        public void setChannelId(String channelId) {
            this.channelId = channelId;
            this.channelName =  BiPlatformManager.getChannelNameById(channelId);
        }
        public String getServerId() {
            return serverId;
        }
        public void setServerId(String serverId) {
            this.serverId = serverId;
            this.serverName =  BiPlatformManager.getServerNameById(serverId);
        }

        public String getDay() {
            return day;
        }

        public void setDay(String day) {
            this.day = day;
        }

        public int getLevel() {
            return level;
        }

        public void setLevel(int level) {
            this.level = level;
        }

        public int getSchool() {
            return school;
        }

        public void setSchool(int school) {
            this.school = school;
        }

        public String getSchoolName() {
            return schoolName;
        }

        public void setSchoolName(String schoolName) {
            this.schoolName = schoolName;
        }

        public float getFirstDayPassRadio() {
            return firstDayPassRadio;
        }

        public void setFirstDayPassRadio(float firstDayPassRadio) {
            this.firstDayPassRadio = firstDayPassRadio;
        }

        public float getFirstWeekPassRadio() {
            return firstWeekPassRadio;
        }

        public void setFirstWeekPassRadio(float firstWeekPassRadio) {
            this.firstWeekPassRadio = firstWeekPassRadio;
        }

        public float getSecondWeekPassRadio() {
            return secondWeekPassRadio;
        }

        public void setSecondWeekPassRadio(float secondWeekPassRadio) {
            this.secondWeekPassRadio = secondWeekPassRadio;
        }

        public float getFirstMonthPassRadio() {
            return firstMonthPassRadio;
        }

        public void setFirstMonthPassRadio(float firstMonthPassRadio) {
            this.firstMonthPassRadio = firstMonthPassRadio;
        }

        public int getFirstDayPassNum() {
            return firstDayPassNum;
        }

        public void setFirstDayPassNum(int firstDayPassNum) {
            this.firstDayPassNum = firstDayPassNum;
        }

        public int getFirstWeekPassNum() {
            return firstWeekPassNum;
        }

        public void setFirstWeekPassNum(int firstWeekPassNum) {
            this.firstWeekPassNum = firstWeekPassNum;
        }

        public int getSecondWeekPassNum() {
            return secondWeekPassNum;
        }

        public void setSecondWeekPassNum(int secondWeekPassNum) {
            this.secondWeekPassNum = secondWeekPassNum;
        }

        public int getFirstMonthPassNum() {
            return firstMonthPassNum;
        }

        public void setFirstMonthPassNum(int firstMonthPassNum) {
            this.firstMonthPassNum = firstMonthPassNum;
        }

        public int getNum() {
            return num;
        }

        public void setNum(int num) {
            this.num = num;
        }
    }

}
